package menupopupplugin2.popup.actions;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class PersistentLayerChoose extends CustomWizardPage {
	private Composite container;
	protected Button rdSpringJDBC;
	protected Button rdHibernate;
	private boolean isHibernate;

	public PersistentLayerChoose() {
		super("PersistentLayerChoose");
		setTitle("Method to input model layer page");
		setDescription("This page show you what you want to generate persistent layer. "
				+ "Spring JDBC or Hibernate framework");
	}

	@Override
	public void createControl(Composite parent) {
		container = new Composite(parent, SWT.NULL);
		GridLayout layout = new GridLayout();
		container.setLayout(layout);
		layout.numColumns = 1;

		RdSelectionListener rdSelectionListener = new RdSelectionListener();
		rdSpringJDBC = new Button(container, SWT.RADIO);
		rdSpringJDBC.setText("Spring JDBC");
		rdSpringJDBC.addSelectionListener(rdSelectionListener);

		rdHibernate = new Button(container, SWT.RADIO);
		rdHibernate.setText("Hibernate framework");
		rdHibernate.addSelectionListener(rdSelectionListener);
		// Required to avoid an error in the system

		setControl(container);
		setPageComplete(false);
	}

	private class RdSelectionListener implements SelectionListener {

		@Override
		public void widgetDefaultSelected(SelectionEvent arg0) {

		}

		@Override
		public void widgetSelected(SelectionEvent arg0) {
			setPageComplete(true);
		}

	}

	@Override
	public boolean isFinish() {
		return false;
	}

	public boolean isHibernate() {
		return isHibernate;
	}

	public IWizardPage getNextPage() {
		if (rdHibernate.getSelection())
			isHibernate = true;
		return super.getNextPage();
	}
}